<?php
class Proposition {

	public $id;
	public $libelle;
	public $estReponse;	
	
	
	public function __construct($id='') {
		if($id != ''){
			$this->id = $id;
			$this->load();
		}
	}

	public function load() {
		if(isset($this->id)){
			$db = Database::getInstance();
			$sql= 'SELECT idProposition, 
                                      libelle,
                                      estReponse,
                                      date
                               FROM proposition
			       WHERE idProposition = "'.$this->id.'"';					
						  
						  
			if ($result = $db->fetch($sql)){				
				$this->libelle = $result[0]['libelle'];					
				$this->estReponse = $result[0]['estReponse'];	
				return true;
			}
			return false;	
		}
	}
	
	public function __toString(){
		return $this->libelle.' '.$this->estReponse;
	
	}
	
	
	public static function getAll() {
		
	}
	
		
	public function addProposition($libelle,$estReponse){
	/* On �chappe les information ins�r�es par l'utilisateur*/
		
		$db = Database::getInstance();
		$sql= 'INSERT INTO `proposition` (
		`idProposition` ,
		`libelle` ,
                `estReponse` ,
                `date`
		)
		VALUES 
		(
		NULL ,
		"'.$libelle.'",	
                "'.$estReponse.'",	     
		CURRENT_TIMESTAMP
		)';
		
		if($db->exec($sql)){
			return $db->lastInsertId();
		}
		
		return false;
		
	}
	
	
}

?>